const { sys_role, op } = require("../../middleware/baseModel");
const { getMd5 } = require("../../tool/funTool");
module.exports = {
  "GET /sys_role/index": async (ctx, next) => {
    const resList = await sys_role.findAll({ where: { type: 0 } });
    return ctx.success(resList);
  },
  "POST /sys_role/add": async (ctx, next) => {
    let row = ctx.getBody();
    let { name, menus } = row;
    const res = await sys_role.create({ name, menus });

    return ctx.success(res);
  },
  "POST /sys_role/edit": async (ctx, next) => {
    let row = ctx.getBody();

    let { id, name, menus } = row;

    const res = await sys_role.update(
      { name, menus },
      {
        where: {
          id: id,
        },
      }
    );
    return ctx.success(res);
  },
  "POST /sys_role/del": async (ctx, next) => {
    let id = ctx.get("id");
    const res = await sys_role.destroy({
      where: {
        id: id,
      },
    });
    return ctx.success(res);
  },
};
